Trò chơi Tic-Tac-Toe, game đánh caro full source code
53.542 lượt xem;
- PlayerDiamond.cs
- Scripts /
- Shared Assets /
- Demos /
- Photon Unity Networking /
- Assets /
- project /
1 using UnityEngine;
2 using System.Collections;
3
4 public class PlayerDiamond : MonoBehaviour
5 {
6 #region Properties
7 public Transform HeadTransform;
8 public float HeightOffset = 0.5f;
9 #endregion
10
11 #region Members
12 PhotonView m_PhotonView;
13 PhotonView PhotonView
14 {
15 get
16 {
17 if( m_PhotonView == null )
18 {
19 m_PhotonView = transform.parent.GetComponent<PhotonView>();
20 }
21
22 return m_PhotonView;
23 }
24 }
25
26 Renderer m_DiamondRenderer;
27 Renderer DiamondRenderer
28 {
29 get
30 {
31 if( m_DiamondRenderer == null )
32 {
33 m_DiamondRenderer = GetComponentInChildren<Renderer>();
34 }
35
36 return m_DiamondRenderer;
37 }
38 }
39
40 float m_Rotation;
41 float m_Height;
42 #endregion
43
44 #region Update
45 void Start()
46 {
47 m_Height = HeightOffset;
48
49 if( HeadTransform != null )
50 {
51 m_Height += HeadTransform.position.y;
52 }
53 }
54
55 void Update()
56 {
57 UpdateDiamondPosition();
58 UpdateDiamondRotation();
59 UpdateDiamondVisibility();
60 }
61
62 void UpdateDiamondPosition()
63 {
64 Vector3 targetPosition = Vector3.zero;
65
66 if( HeadTransform != null )
67 {
68 targetPosition = HeadTransform.position;
69 }
70
71 targetPosition.y = m_Height;
72
73 if( float.IsNaN( targetPosition.x ) == false && float.IsNaN( targetPosition.z ) == false )
74 {
75 transform.position = Vector3.Lerp( transform.position, targetPosition, Time.deltaTime * 10f );
76 }
77 }
78
79 void UpdateDiamondRotation()
80 {
81 m_Rotation += Time.deltaTime * 180f;
82 m_Rotation = m_Rotation % 360;
83
84 transform.rotation = Quaternion.Euler( 0, m_Rotation, 0 );
85 }
86
87 void UpdateDiamondVisibility()
88 {
89 DiamondRenderer.enabled = true;
90
91 if( PhotonView == null || PhotonView.isMine == false )
92 {
93 DiamondRenderer.enabled = false;
94 }
95 }
96 #endregion
97 }
2 using System.Collections;
3
4 public class PlayerDiamond : MonoBehaviour
5 {
6 #region Properties
7 public Transform HeadTransform;
8 public float HeightOffset = 0.5f;
9 #endregion
10
11 #region Members
12 PhotonView m_PhotonView;
13 PhotonView PhotonView
14 {
15 get
16 {
17 if( m_PhotonView == null )
18 {
19 m_PhotonView = transform.parent.GetComponent<PhotonView>();
20 }
21
22 return m_PhotonView;
23 }
24 }
25
26 Renderer m_DiamondRenderer;
27 Renderer DiamondRenderer
28 {
29 get
30 {
31 if( m_DiamondRenderer == null )
32 {
33 m_DiamondRenderer = GetComponentInChildren<Renderer>();
34 }
35
36 return m_DiamondRenderer;
37 }
38 }
39
40 float m_Rotation;
41 float m_Height;
42 #endregion
43
44 #region Update
45 void Start()
46 {
47 m_Height = HeightOffset;
48
49 if( HeadTransform != null )
50 {
51 m_Height += HeadTransform.position.y;
52 }
53 }
54
55 void Update()
56 {
57 UpdateDiamondPosition();
58 UpdateDiamondRotation();
59 UpdateDiamondVisibility();
60 }
61
62 void UpdateDiamondPosition()
63 {
64 Vector3 targetPosition = Vector3.zero;
65
66 if( HeadTransform != null )
67 {
68 targetPosition = HeadTransform.position;
69 }
70
71 targetPosition.y = m_Height;
72
73 if( float.IsNaN( targetPosition.x ) == false && float.IsNaN( targetPosition.z ) == false )
74 {
75 transform.position = Vector3.Lerp( transform.position, targetPosition, Time.deltaTime * 10f );
76 }
77 }
78
79 void UpdateDiamondRotation()
80 {
81 m_Rotation += Time.deltaTime * 180f;
82 m_Rotation = m_Rotation % 360;
83
84 transform.rotation = Quaternion.Euler( 0, m_Rotation, 0 );
85 }
86
87 void UpdateDiamondVisibility()
88 {
89 DiamondRenderer.enabled = true;
90
91 if( PhotonView == null || PhotonView.isMine == false )
92 {
93 DiamondRenderer.enabled = false;
94 }
95 }
96 #endregion
97 }